#!/bin/bash
if [ "$#" -lt 2 ]; then
  echo "usage $0 [version] <out dir> <range>"
  exit 1
fi

RED="\e[1;31m"
NONE="\e[0m"

CHECK_PATCH=/home/hitmoon/qemu/scripts/checkpatch.pl

VER=""
OUT=""
RAN=""

if [ "$#" -eq 3 ]
then
 VER="-v${1}"
 OUT="-o $2"
 RAN="-$3"
else
 OUT="-o $1"
 RAN="-$2"
fi

echo "Generating patches ..."
git format-patch -s --cover-letter ${VER} ${OUT} ${RAN} | tee patch.list
echo "Done"
echo "*****************************************************************"
while read p
do
  if [[ "$p" =~ 0000 ]]; then
     continue;
  fi
  echo -e "${RED}Checking patch: $p ... $NONE"
  $CHECK_PATCH $p
done < patch.list

